home *** CD-ROM | disk | FTP | other *** search
- /* ================================================================= */
-
- /* Module name: allocator.c */
-
- /* ----------------------------------------------------------------- */
-
- #define ALLOCATE_GLOBALS
-
- #include "general.h"
-
- extern struct NewMenu menu1[];
-
-
- UBYTE *alert_message_p =
-
- "\x00\x4A\x14"
- "********* RECOVERABLE ALERT - CANNOT RUN EXAMPLE PROGRAM *********" "\x00\x01"
-
-
- "\x00\x4A\x24"
- "Version 37 or upwards of Gadtools and ASL libraries required" "\x00\x01"
-
-
- "\x0\x4A\x34"
- "******* PRESS LEFT OR RIGHT MOUSE BUTTON TO CONTINUE *******" "\x00";
-
-
- #define DISPLAY_COUNT 12
-
- UBYTE (*display_list[])() = {
-
- OpenInt,
- OpenGraphics,
- OpenGadtools,
- LockScreen,
- GetVisInfo,
- CreateWindow,
- CreateMenu,
- CreateMenuLayout,
- InstallMenu,
- CreateTimerReplyPort,
- CreateTimerRequestBlock,
- OpenTimer
-
- };
-
-
-
- main(int argc, char *argv[])
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(g_resource_stack_p=CreateStack(void *))) error_number=NO_STACK;
-
- else {
-
- /* attempt to allocate resources... */
-
- error_number=AllocateResource(DISPLAY_COUNT,display_list);
-
- if (error_number) DisplayAlert(RECOVERY_ALERT,alert_message_p,80);
-
- else error_number=AmigaProg();
-
- while(!PopStack(g_resource_stack_p,g_function)) g_function();
-
- KillStack(g_resource_stack_p);
-
- }
-
- return(0);
-
- } /* Logical end of program */
-
- /* ----------------------------------------------------------------- */
-
- UBYTE AllocateResource(UBYTE count,UBYTE (*list[])())
-
- {
-
- UBYTE i, error_number;
-
- for (i=0;i<count;i++)
-
- {
-
- if(error_number=list[i]())
-
- i=count; /* force exit from loop */
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
-
- UBYTE OpenInt(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(IntuitionBase=(struct IntuitionBase *)
- OpenLibrary("intuition.library",INTUITION_VERSION)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=CloseInt;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void CloseInt(void)
-
- {
-
- CloseLibrary((struct Library *)IntuitionBase);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE OpenGraphics(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(GfxBase=(struct GfxBase *)
- OpenLibrary("graphics.library",GRAPHICS_VERSION)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=CloseGraphics;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void CloseGraphics(void)
-
- {
-
- CloseLibrary((struct Library *)GfxBase);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE LockScreen(void)
-
- {
-
- UBYTE error_number=ALLOCATION_ERROR;
-
- if (g_public_screen_p=LockPubScreen(NULL))
-
- {
-
- g_viewport_p=&g_public_screen_p->ViewPort;
-
- error_number=NO_ERROR;
-
- g_function=UnlockScreen;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void UnlockScreen(void)
-
- {
-
- UnlockPubScreen(NULL,g_public_screen_p);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE CreateWindow(void)
-
- {
-
- UBYTE error_number=ALLOCATION_ERROR;
-
- g_window_p=OpenWindowTags(NULL,
- WA_Left,0, WA_Top,0,
- WA_Width,WINDOW_WIDTH, WA_Height, WINDOW_HEIGHT,
- WA_DragBar, FALSE,
- WA_DepthGadget, TRUE,
- WA_CloseGadget, TRUE,
- WA_SmartRefresh, TRUE,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MENUPICK |
- IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
- WA_Title, "Timer Device Example - see Paul Overaa's Programming Tips",
- WA_PubScreen, g_public_screen_p,
- TAG_END);
-
- if (g_window_p)
-
- {
-
- GT_RefreshWindow(g_window_p,NULL);
-
- error_number=NO_ERROR;
-
- g_rastport_p=g_window_p->RPort;
-
- g_function=KillWindow;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void KillWindow(void)
-
- {
-
- CloseWindow(g_window_p);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE OpenGadtools(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(GadToolsBase=OpenLibrary("gadtools.library",GADTOOLS_VERSION)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=CloseGadtools;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void CloseGadtools(void)
-
- {
-
- CloseLibrary((struct Library *)GadToolsBase);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE GetVisInfo(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(g_visual_info_p=GetVisualInfo(g_public_screen_p,TAG_END)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=FreeVisInfo;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void FreeVisInfo(void)
-
- {
-
- FreeVisualInfo(g_visual_info_p);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE CreateMenu(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(g_menu_p=CreateMenus(menu1,TAG_END)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=ReleaseMenu;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void ReleaseMenu(void)
-
- {
-
- FreeMenus(g_menu_p);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE CreateMenuLayout(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(LayoutMenus(g_menu_p,g_visual_info_p,TAG_END)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
-
- /* Function must be tested for success but
- no deallocation operations are needed! */
-
- }
-
- return(error_number);
-
-
- }
-
- /* ----------------------------------------------------------------- */
-
- UBYTE InstallMenu(void)
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if(!(SetMenuStrip(g_window_p,g_menu_p)))
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=RemoveMenu;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------- */
-
- void RemoveMenu(void)
-
- {
-
- ClearMenuStrip(g_window_p);
-
- }
-
- /* ----------------------------------------------------------------------- */
-
- UBYTE CreateTimerReplyPort()
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if((g_timer_reply_port_p=CreatePort(TIMERNAME,0))==NULL)
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=DeleteTimerReplyPort;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------------- */
- void DeleteTimerReplyPort()
-
- {
-
- DeletePort(g_timer_reply_port_p);
-
- }
-
- /* ----------------------------------------------------------------------- */
- UBYTE CreateTimerRequestBlock()
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- g_timer_request_p=(struct timerequest *)
- CreateExtIO(g_timer_reply_port_p,sizeof(struct timerequest));
-
- if (g_timer_request_p==NULL) error_number=ALLOCATION_ERROR;
-
- else {
-
- g_function=DeleteTimerRequestBlock;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------------- */
-
- void DeleteTimerRequestBlock()
-
- {
-
- DeleteExtIO((struct IORequest *)g_timer_request_p);
-
- }
-
- /* ----------------------------------------------------------------------- */
-
- UBYTE OpenTimer()
-
- {
-
- UBYTE error_number=NO_ERROR;
-
- if((OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *)g_timer_request_p,0))!=NULL)
-
- error_number=ALLOCATION_ERROR;
-
- else {
-
- g_timer_request_p->tr_node.io_Command=TR_ADDREQUEST;
-
- g_function=CloseTimer;
-
- PushStack(g_resource_stack_p,g_function);
-
- }
-
- return(error_number);
-
- }
-
- /* ----------------------------------------------------------------------- */
-
- void CloseTimer()
-
- {
-
- CloseDevice((struct IORequest *)g_timer_request_p);
-
-
- }
-
- /* ----------------------------------------------------------------------- */
-